import AjaxUtil from './ajaxUtil.js';
function initCity(){
let ajax=new AjaxUtil();
let url="nativePlace.servlet?code="+document.getElementById("province").value;
ajax.getJson(url,(xhr)=>{
	let json=xhr.response;
	let node =document.getElementById("city");
	node.innerHTML="";
	if(json.msg!="no data"){
		let defaultOpation=document.createElement("option");
		defaultOpation.value="0000";
		defaultOpation.innerHTML="请选择城市";
		defaultOpation.selected=true;
		node.appendChild(defaultOpation);
		json.result.forEach((item)=>{
			let option=document.createElement("option");
			option.value=item.code;
			
			option.innerHTML=item.name;
			node.appendChild(option);
		});
	}
});
}
function init(){
	document.getElementById("province").addEventListener("change",initCity,false);
    document.getElementById("email").addEventListener("focus",()=>{
        document.getElementById("email_error_msg").innerHTML="";
        document.getElementById("email_error_img").classList.remove("okimg");
        document.getElementById("email_error_img").classList.remove("errorimg");
        document.getElementById("email_error_msg").classList.remove("okMessage");
        document.getElementById("email_error_msg").classList.remove("errorMessage");
    },false);
let regex=/^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.[a-zA-Z0-9]{2,6}$/;
document.getElementById("email").addEventListener("blur",()=>{
 
    if(regex.test(document.getElementById("email").value)){
       
        document.getElementById("email_error_msg").innerHTML="邮箱格式符合要求";
        document.getElementById("email_error_msg").classList.add("okMessage");
        document.getElementById("email_error_img").classList.add("okimg");
        }else{
            document.getElementById("email_error_msg").innerHTML="邮箱格式不符合要求";
            document.getElementById("email_error_msg").classList.add("errorMessage");
            document.getElementById("email_error_img").classList.add("errorimg");

        }
},false);
         let yh=/^[a-zA-Z0-9_]{4,16}$/;
         document.getElementById("userName").addEventListener("blur",()=>{
 
            if(yh.test(document.getElementById("userName").value)){
               
                document.getElementById("usererror_msg").innerHTML="用户名格式符合要求";
                document.getElementById("usererror_msg").classList.add("okMessage");
                document.getElementById("usererror_img").classList.add("okimg");
                }else{
                    document.getElementById("usererror_msg").innerHTML="用户名格式不符合要求,请输入4到16位的数字或字母";
                    document.getElementById("usererror_msg").classList.add("errorMessage");
                    document.getElementById("usererror_img").classList.add("errorimg");
        
                }
             if(document.getElementById("userName").value=="") {
                document.getElementById("usererror_msg").innerHTML="用户名不能为空";
             } 
        },false);
        document.getElementById("userName").addEventListener("focus",()=>{
            document.getElementById("usererror_msg").innerHTML="";
            document.getElementById("usererror_img").classList.remove("okimg");
            document.getElementById("usererror_img").classList.remove("errorimg");
            document.getElementById("usererror_msg").classList.remove("okMessage");
            document.getElementById("usererror_msg").classList.remove("errorMessage");
        },false);
        document.getElementById("nicheng").addEventListener("blur",()=>{
 
            if(document.getElementById("nicheng").value==""){
               
                document.getElementById("nichengmsg").innerHTML="昵称不能为空";
                document.getElementById("nichengmsg").classList.add("errorMessage");
                document.getElementById("nichengimg").classList.add("errorimg");
    
                }
           
        },false);
        document.getElementById("nicheng").addEventListener("focus",()=>{
            document.getElementById("nichengmsg").innerHTML="";
            document.getElementById("nichengimg").classList.remove("okimg");
            document.getElementById("nichengimg").classList.remove("errorimg");
            document.getElementById("nichengmsg").classList.remove("okMessage");
            document.getElementById("nichengmsg").classList.remove("errorMessage");
        },false);
        let pass=/^.{8,20}$/;
        document.getElementById("password").addEventListener("blur",()=>{
 
            if(document.getElementById("password").value!=""&&pass.test(document.getElementById("password").value)){
               
                document.getElementById("pderror_msg").innerHTML="密码格式正确";
                document.getElementById("pderror_msg").classList.add("okMessage");
                document.getElementById("pderror_img").classList.add("okimg");
    
                }else{
                    document.getElementById("pderror_msg").innerHTML="密码格式不对,请输入8到20个任意字符";
                    document.getElementById("pderror_msg").classList.add("errorMessage");
                    document.getElementById("pderror_img").classList.add("errorimg");
                }
           
        },false);
        document.getElementById("password").addEventListener("focus",()=>{
            document.getElementById("pderror_msg").innerHTML="";
            document.getElementById("pderror_img").classList.remove("okimg");
            document.getElementById("pderror_img").classList.remove("errorimg");
            document.getElementById("pderror_msg").classList.remove("okMessage");
            document.getElementById("pderror_msg").classList.remove("errorMessage");
        },false);
        document.getElementById("rePassword").addEventListener("blur",()=>{
 
            if(document.getElementById("rePassword").value==document.getElementById("password").value){
               if(document.getElementById("rePassword").value==""){
                document.getElementById("againerror_msg").innerHTML="密码不能为空";
                document.getElementById("againerror_msg").classList.add("errorMessage");
                document.getElementById("againerror_img").classList.add("errorimg");
               }else{
                document.getElementById("againerror_msg").innerHTML="密码一致";
                document.getElementById("againerror_msg").classList.add("okMessage");
                document.getElementById("againerror_img").classList.add("okimg");

               }
               
                  
                }else{
                    document.getElementById("againerror_msg").innerHTML="密码不一致";
                    document.getElementById("againerror_msg").classList.add("errorMessage");
                    document.getElementById("againerror_img").classList.add("errorimg");
                }
           
        },false);
        document.getElementById("rePassword").addEventListener("focus",()=>{
            document.getElementById("againerror_msg").innerHTML="";
            document.getElementById("againerror_img").classList.remove("okimg");
            document.getElementById("againerror_img").classList.remove("errorimg");
            document.getElementById("againerror_msg").classList.remove("okMessage");
            document.getElementById("againerror_msg").classList.remove("errorMessage");
        },false);
        let pne=/^[1][3,4,5,7,8][0-9]{9}$/;
        document.getElementById("phone").addEventListener("blur",()=>{
 
            if(pne.test(document.getElementById("phone").value)){
               
                document.getElementById("phone_error_msg").innerHTML="手机号格式正确";
                document.getElementById("phone_error_msg").classList.add("okMessage");
                document.getElementById("phone_error_img").classList.add("okimg");
    
                }else{
                    document.getElementById("phone_error_msg").innerHTML="手机号格式不对";
                    document.getElementById("phone_error_msg").classList.add("errorMessage");
                    document.getElementById("phone_error_img").classList.add("errorimg");
                }
           
        },false);
        document.getElementById("phone").addEventListener("focus",()=>{
            document.getElementById("phone_error_msg").innerHTML="";
            document.getElementById("phone_error_img").classList.remove("okimg");
            document.getElementById("phone_error_img").classList.remove("errorimg");
            document.getElementById("phone_error_msg").classList.remove("okMessage");
            document.getElementById("phone_error_msg").classList.remove("errorMessage");
        },false);
};
window.addEventListener("load",init,false);